using System;
using System.Collections.Generic;
using System.Text;
using Ghasam.Business.Domain.Entity;
using NHibernate;
using NHibernate.Expression;

namespace Ghasam.Business.DAO.Impl
{
    public class GoodsDao : DaoBase<Goods>, IGoodsDao
    {

        #region IGoodsDao Members

        public int CountGoods()
        {
            ICriteria crit = base.Session.CreateCriteria(typeof(Goods));
            crit.Add(Expression.Eq("IsDeleted", false));
            crit.SetProjection(Projections.Count("Id"));
            return crit.UniqueResult<int>();
        }

        public IList<Goods> GetGoods(int pageSize, int pageNumber)
        {
            ICriteria crit = base.Session.CreateCriteria(typeof(Goods));
            crit.Add(Expression.Eq("IsDeleted", false));
            return crit.SetMaxResults(pageSize).SetFirstResult(pageSize * pageNumber).List<Goods>();
        }
        public IList<Goods> SortGoods(string param ,bool asc)
        {
            Order dir = new Order(param,asc);
            ICriteria crit = base.Session.CreateCriteria(typeof(Goods));
            crit.AddOrder(dir);
            return crit.List<Goods>();
        }

        #endregion
    }
}
